package com.zkingsoft.services.web.impl;

import com.zkingsoft.services.web.WebArticleService;
import com.zkingsoft.pojo.PaginationVO;
import com.zkingsoft.model.web.WebArticle;
import com.zkingsoft.dao.web.WebArticleDao;
import org.springframework.stereotype.Service;
import java.util.Map;
import com.zkingsoft.exception.GlobleException;
import com.zkingsoft.util.ModelUtils;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;

/**
 * This field was generated by Zking.software.Codegen.
 * @date 2016-12-01 10:36
 */
@Service("webArticleService")
public class  WebArticleServiceImpl implements    WebArticleService  {

	
	@Autowired
	private WebArticleDao webArticleDao;
	
	
	@Override
	public int add(WebArticle webArticle){
		
		return webArticleDao.insert(webArticle);
		
	}
	
	@Override
	public int batchAdd(List<WebArticle>  webArticleList) {
		return webArticleDao.batchInsert(webArticleList);
	}
	
	
   	
    @Override
	public int modifyByMap(WebArticle oldWebArticle
	,WebArticle newWebArticle){
	
		if (!ModelUtils.isModified(oldWebArticle, newWebArticle)) {
			return 1;
		}
		Map<String, Object> modifyMap=null;
		try {
			modifyMap = ModelUtils.comparePojo2Map(oldWebArticle, newWebArticle);
		} catch (Exception e) {
			throw new GlobleException("数据对比失败");
		}
		if (modifyMap.size() > 0) {
			modifyMap.put("artId", oldWebArticle.getArtId());
			webArticleDao.updateByMap(modifyMap);
		}
		return 1;
	}
	
	@Override
	public int modifyByModel(WebArticle webArticle){
	
		return webArticleDao.updateByModel(webArticle);
	
	}
	
	
	
	@Override
	public int remove(List<Long> list){
	
		return webArticleDao.deleteByIds(list);
	
	}

	@Override
	public int removeById(Long artId){
	
		return webArticleDao.deleteById(artId);
	
	}
	
	@Override
	public int removeByModel(WebArticle webArticle){
	
		return webArticleDao.deleteByModel(webArticle);
	
	}
	
	
	@Override
	public List<WebArticle> findInPage(WebArticle webArticle,  PaginationVO pageVo){
	
		return webArticleDao.selectInPage(webArticle , pageVo);
	
	}
	
	@Override
	public List<WebArticle> findByModel(WebArticle webArticle){
	
		return webArticleDao.selectByModel(webArticle);
	
	}
	
	@Override
	public int  findTotal(WebArticle webArticle){
	
		return webArticleDao.selectTotalRecord(webArticle);
	
	}
	
	@Override
	public WebArticle  findById(Long artId){
	
		return webArticleDao.selectById(artId);
	
	}

   	
	
	
}